package com.smart.six.locale.messagesource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.MessageFormat;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * 测试国际化信息格式化串
 *
 * @author junrui.wang
 * @create 2018/7/13
 */
public class TestMessageSource {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("com/smart/six/locale/messagesource/beans.xml");

        //无需分别加载不同语言，不同国家/地区的本地化资源，仅仅通过资源名就可以加载整套国际化信息资源文件。
        //无需显示使用MessageFormat操作国际化信息
        MessageSource ms = (MessageSource) ac.getBean("myMessageSource");

        Object[] params = {"John", new GregorianCalendar().getTime()};

        String s1 = ms.getMessage("common.common", params, Locale.getDefault());
        String s2 = ms.getMessage("common.common", params, Locale.US);
        String s3 = ms.getMessage("common.common", params, Locale.CHINA);

        System.out.println("default:" + s1);
        System.out.println("US:" + s2);
        System.out.println("China:" + s3);
    }
}
